package com.hqyj.springBoot.modules.account.controller;


import com.hqyj.springBoot.modules.common.vo.Result;
import com.hqyj.springBoot.modules.account.entity.Role;
import com.hqyj.springBoot.modules.account.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class RoleController {

    @Autowired
    private RoleService roleService;

    /**
     * 127.0.0.1/api/role ----post
     * {"createDate":"2022-09-11 11:21:23","roleName":"test01"}
     */
    @PostMapping(value = "/role",consumes = MediaType.APPLICATION_JSON_VALUE)
    public Result<Role> insertRole(@RequestBody Role role){
        return roleService.insertRole(role);
    }

    /**
     * 127.0.0.1/api/role ----put
     * {"createDate":"2022-09-11 15:21:23","roleName":"test001","roleId":5}
     */
    @PutMapping(value = "/role",consumes = MediaType.APPLICATION_JSON_VALUE)
    Result<Role> updateRole(@RequestBody Role role){
        return roleService.updateRole(role);
    }

    /**
     * 127.0.0.1/api/role/roleId ---delete
     */
    @DeleteMapping("/role/{roleId}")
    Result<Object> deleteRoleById(@PathVariable int roleId){
        return roleService.deleteRoleById(roleId);
    }


    /**
     * 127.0.0.1/api/role/roleId ---get
     */
    @GetMapping("/role/{roleId}")
    Role selectRoleById(@PathVariable int roleId){
        return roleService.selectRoleById(roleId);
    }

    /**
     * 127.0.0.1/api/role/roleId ---get
     */
    @GetMapping("/roles")
    List<Role> selectRoleById(){
        return roleService.getAllRolls();
    }

}
